function sourcesGetter(){
	var text;
	var start = 20;
	var stop = 30;
	var root_url = 'http://www.dasregistry.org/';// "http://localhost:8080/dasregistry/";//'http://www.dasregistry.org/';//'http://localhost:8080/dasregistry/';//change
	// this to
	// http://www.dasregistry.org/
var server_url = root_url + 'das/sources?';
var caps = new Array();
caps[0] = "sources";
caps[1] = "stylesheet";
caps[2] = "features";
caps[3] = "types";
caps[4] = "sequence";
caps[5] = "entry_points";
caps[6] = "alignment";
caps[7] = "structure";
caps[8] = "interaction";
caps[9] = "unknown_segment";
caps[10] = "unknown_feature";
caps[11] = "error_segment";
caps[12] = "maxbins";
caps[13] = "cors";
caps[14] = "feature_by_id";
/**
 * This function will be executed in case of error
 */
var error_response = function() {
	//alert('Bad response, Wrong URL?, No Sequence XML?');
	text='<font color=\"red\">The search service is down please use the search functionality at <a href="listServices.jsp\">List Sources</a> instead</font>';
	$("#sourcesDiv").html(text);
	$("#coordinatesDiv").html(text);
	$("#ajaxLoaderSources").html('');
	$("#ajaxLoaderCoordinates").html('');
	
};
	//alert("sourcesGetter constructor");
this.getSourcesHTML=function(){//start, end, url){
	
var d = new Date();
	JSDAS.sources(escape(server_url + '&rows=' + start + '-'
			+ stop + '&neverused=' + d.getTime()), response,
			this.error_response);
	

};	



var response=function(res){ //alert('calling response method');
// var total=res.total;
// text+="total="+total;
// text = '<link rel=\"stylesheet\" type=\"text/css\"
// href=\"stylesheet.css\" />';
var text = '';// reset the data
text += '<div id=\"table\"><table id=\"list\"class=\"dastable\">';
// get info on sources size from sources attr
totalSources = res.total;

// print headers

text += '<tr class="row0">';

text += '<td><b>pos</pos></td>';
text += '<td><b>id</b></td>';

// text +='<td><b>clients</b></td>';

text += '<td><b>';
text += 'nickname';

text += '</b></td>';
text+='<td><b>status</b></td>';

// text +='<td><b>';
// text += 'status';
// text +='</b></td>';

text += '<td><b>';
text += 'description';
text += '</b></td>';

text += '<td colspan=\'' + caps.length + '\'>Capabilities</td>';

text += '<td><b>types';
text += '</b></td>';

text += '<td>Specification</td>';
text += '<td>Project</td>';
text += '<td>coordinateSystem</td>';
text += '</tr>';

var row = 'row0';
if(res.SOURCE==undefined || res.SOURCE.length==0){
	$("#ajaxLoaderSources").html('');
	return text="No sources returned for this query";
}else{
for ( var i = 0; i < res.SOURCE.length; i++) {

	// need to find the number of coordinate systems for
	// this source to see how many rowspans tds need to be

	var coordinates = res.SOURCE[i].VERSION[0].COORDINATES;
	if (coordinates) {
		var numberOfCoords = coordinates.length;
		var rowspan = 1;
		if (numberOfCoords) {
			rowspan = numberOfCoords;
		}
	}
	
	var propMap=createPropertyMap(res.SOURCE[i].VERSION[0].PROP);
	
	//get the number of days before deletion if specified
	//if not then valid else invalid
	var daysBeforeDeletion=60;
	if(propMap['daysBeforeDeletion']){
	daysBeforeDeletion=propMap['daysBeforeDeletion'];	
	//alert(daysBeforeDeletion);
	}
	
	var versionUri=res.SOURCE[i].VERSION[0].uri;
	var sourceId=res.SOURCE[i].uri;
	// alert('number of coords='+numberOfCoords);

	for ( var l = 0; l < rowspan; l++) {

		if (i % 2 == 0) {
			row = 'row1';
		} else {
			row = 'row0';
		}
		text += '<tr class=\"' + row + '\">';
		var position = start + i;
		if (l == 0) {// only do this loop once for a
						// source
			text += '<td rowspan=\'' + rowspan + '\'>'
					+ position + '</td>';
			text += '<td rowspan=\'' + rowspan + '\'>'
					+ res.SOURCE[i].uri;
			
			text+='<div id=\"dassourceactions\" title=\"show details\"><a href=\'showdetails.jsp?auto_id='+sourceId+'\'>';
				text+='<img src=\"img/messagebox_info16x16.png\" border=\"0\"/></a></div>';	
				text+='<div id=\"dassourceactions\" title=\"validate\"><a href=\'validateServer.jsp?auto_id='+sourceId+'\'>';
				text+='<img src=\"img/ok16x16.png\" border=\"0\"/></a></div>';
				
				text+='<div id=\"dassourceactions\" title=\"send to freind\"><a href=\'sendToFriend.jsp?auto_id='+sourceId+'\'>';
				text+='<img src=\"img/mail_post_to16x16.png\" border=\"0\"/></a></div>';	
				
//		<div id="dassourceactions" title="header=[validate] body=[validate the <%=ds.getNickname()%> server]"><a href="validateServer.jsp?auto_id=<%=ds.getId()%>"> 
//			<img 	src="img/ok16x16.png" border="0" alt="validate"
//			onMouseOver="window.status='validate'; return true;"
//			onMouseOut="window.status=' '; return true;"></a>
//			</div>
//		<div id="dassourceactions" title="header=[send to friend] body=[notify a friend about the <%=ds.getNickname()%> server]">
//			<a href="sendToFriend.jsp?auto_id=<%=ds.getId()%>"> 
//			<img src="img/mail_post_to16x16.png" boder="0" alt="edit"
//			onMouseOver="window.status='send to friend'; return true;"
//			onMouseOut="window.status=' '; return true;"></a>
//			</div>
			
			
			
			
					text+= '</td><td rowspan=\'' + rowspan
					+ '\'>' + res.SOURCE[i].title
					+ '</td>'+
					'<td rowspan=\'' + rowspan
					+ '\'>';
			if(daysBeforeDeletion!=60){
				text+='<a href=\"http://www.dasregistry.org/validateServer.jsp?auto_id='+sourceId+'\" title=\''+daysBeforeDeletion+' days before deletion\'><img src=\"img/messagebox_warning.png\"/>Source down/invalid removal in '+daysBeforeDeletion+' days.</a></td>';
			}
			text+='</td>'+
					'<td rowspan=\'' + rowspan
					+ '\'>'+'<a class=\"clickDescription\"  >Show/Hide</a>'
					+'<div class=\'shortdescription\'>'
					+ '<a href=\"'+res.SOURCE[i].doc_href+'\">Further Information</a> '
					+ res.SOURCE[i].description;
			//	+ res.SOURCE[i].description.substring(0,60)+'...';
					+ '</div></td>';
			

			
			
			for (k = 0; k < caps.length; k++) {
				text += '<td rowspan=\'' + rowspan + '\' class=\'noBorder\'>';
				var cap = caps[k];
				// text+=cap;
				var image = '<img class="valid" src=\"' + 'img/clear16.gif' + '\">';// default
				// color
				// for
				// img
				

					var status = propMap[cap];
					var img = '';

					if ('valid' == status)
						img = 'img/green16.gif';
					if ('probably_valid' == status)
						img = 'img/amber16.gif';
					if ('invalid' == status)
						img = 'img/red16.gif';
					if (img == '')
						img = 'img/clear16.gif';

					
					var test_range='';
					if(coordinates){
					test_range=coordinates[0].test_range;
					}
					//chop off the command from the quer_uri oin future will need to get the specific uri as these will be allowed to be different
					var shortQueryUri=res.SOURCE[i].VERSION[0].CAPABILITY[0].query_uri.substring(0,res.SOURCE[i].VERSION[0].CAPABILITY[0].query_uri.lastIndexOf("/"));
					//alert(query_uri);
//					var shortQueryUri=query_uri.replace(cap, "");
//					if((i==0)&&(k==0)){
//						alert(query_uri);
//					alert(shortQueryUri);	
//					}
					text += '<a title=\''+cap+' capability is '+status+'\' href=\"' + getTestUrl(
								shortQueryUri,
								cap,
								test_range) + '\">';
						image = '<img class="valid" src=\"' + img + '\"><\/>';
						
					

				
				text += image + '</td>';

			}
			
			text += '<td rowspan=\'' + rowspan + '\'>';
			
			var idForTypes='no types';
				if(propMap['types']=='valid'){idForTypes=versionUri;//ideally should be just source uri =auto_id but because of mirrored sources need url
				text += '<a class=\"click\"  >Show/Hide Types</a>';
				}
			text += '<div class=\"ajaxTypes\" id=\"' + idForTypes + '\"></div>';
			text += '</td>';// <a
							// class="click">Expand/Contract</a>
			// <div class="ajaxTypes" id="<%=auto_id
			// %>"></div>
			text += '<td rowspan=\'' + rowspan + '\'>'+propMap['spec']+'</td>';
			var projectIcon=propMap['projectIcon'];
			if(projectIcon!=undefined){
			var projectId=projectIcon.substring(projectIcon.indexOf('=')+1);
			
			text += '<td rowspan=\'' + rowspan + '\'><a href=\'http://www.dasregistry.org/showProjectDetails.jsp?project_id='+projectId+'\'\'>'+'<img src=\''+projectIcon+'\'></a></td>';
			}else{
			text+=	'<td rowspan=\'' + rowspan + '\'></td>';
			}	
			}// end of l==0 loop for listing source once as
			// span should take care of filling in the rows
			// below.
		// alert('coordinates length='+coordinates.length);

		if (coordinates == undefined || coordinates == null) {// fill
																// with
																// empty
																// tds
																// though
																// technically
																// why
																// sources
																// have
																// no
																// coords
																// is
																// bad
																// and
																// should
																// be
																// corrected
																// -
																// happening
																// with
																// mirrored
																// sources
																// only
			text += '<td >' + '</td>' + '<td >' + '</td>'
					+ '<td >'

					+ '</td>' + '<td >'

					+ '</td>' + '<td >'

					+ '</td>';
		} else {

			text += '<td >' + '<a href=\''
					+ coordinates[l].uri + '\'>'
					+ coordinates[l].textContent + '</a>'
					+ '</td>';

		}

		text += '</tr>';
	}
	;
}
}
text += '</table></div>';
$("#sourcesDiv").html(text);// need to set html here as the
							// response from server may take
							// a while
// $('#sourcesDiv a').click(function(){alert('click now
// works')});
//
$(".click").click(function() {

	$(this).next().toggleClass("ajaxTypesLarge");
	var id = $(this).next().attr("id");
	// alert("id="+id);
		if ((id != undefined) && (id != "")) {
			$(this).next().load("types.jsp" + "?id=" + id);
	}
		});

$(".clickDescription").click(function() {
	$(this).next().toggleClass("longdescription");
	
		});

//$(".shortdescription").hover(function (){
//	$(this).toggleClass("longdescription")
//
//});
// $('a img').tooltip();
$("#ajaxLoaderSources").html('');
$('#totalSourcesDiv').html(
		start + '-' + stop + ' of ' + totalSources);
return text;
};

function createPropertyMap(properties){
	var map=new Object();
	if(properties.length>0 && properties!=null && properties!=undefined){
	for(var propIndex=0;propIndex<properties.length; propIndex++){
	var name=properties[propIndex].name;
	var value=properties[propIndex].value;
	map[name]=value;
	//alert(name +'='+value);
	}
	}
	return map;
}

function getTestUrl(baseuri, command, testCode) {
	var testurl;
	var extension;
	// alert(baseuri+' ' +command+' '+testCode);
	//should change this to get the test url from the das/sources/dsn/capabilities uri?? will this confuse clients?
	if (command == "sources") {
		extension = "sources";
	}
	
	if (command == "stylesheet") {
		extension = command;
	}
	
	if (command == "features") {
		extension = command + "?segment=" + testCode;
	}
	
	if (command == "types") {
		extension = command;
	}
	
	if (command == "sequence") {
		extension = command + "?segment=" + testCode;
	}
	
	if (command == "entry_points") {
		extension = command;
	}
	
	if (command == "alignment") {
		extension = command + "?query=" + testCode;
	}
	
	if (command == "structure") {
		extension = command + "?query=" + testCode;
	}
	
	if (command == "interaction") {
		extension = command + "?interactor=" + testCode;
	}
	
	if (command == "unknown_segment") {
		extension = "features" + "?segment="
				+ 'invalidTestCode' + ":1,1000";
	}
	
	if (command == "unknown_feature") {
		extension = "features" + "?feature_id="
				+ 'invalidTestCode';
	}
	
	if (command == "error_segment") {
		extension = "features" + "?segment="
				+ 'invalidTestCode' + ":1,1000";
	}
	
	if (command == "maxbins") {
		extension = "features" + "?segment=" + testCode
				+ ";maxbins=1";
	}
	if(command == "feature_by_id"){
		extension = "features" + "?feature_id=";
	}
	

	testurl = baseuri +'\/'+extension;

	return testurl;
}


};
	


